package ch.ethz.fcl.metrobuzz.controller.gui.swing;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import net.miginfocom.swing.MigLayout;
import ch.ethz.fcl.metrobuzz.data.roadnetwork.hierarchy.Stroke;

public class DirectionPanel extends JPanel{
	private static final long serialVersionUID = 1L;

	JCheckBox north;
	JCheckBox south;
	JCheckBox east;
	JCheckBox west;
	JCheckBox dangling;

	public DirectionPanel() {
		super(new MigLayout());

		setBackground(Color.lightGray);
		setBorder(BorderFactory.createTitledBorder("Direction"));

		DirectionListener dl = new DirectionListener();
		
		north = new JCheckBox("Show North", Stroke.NORTH);
		north.addChangeListener(dl);
		
		south = new JCheckBox("Show South", Stroke.SOUTH);
		south.addChangeListener(dl);
		
		east = new JCheckBox("Show East", Stroke.EAST);
		east.addChangeListener(dl);
		
		west = new JCheckBox("Show West", Stroke.WEST);
		west.addChangeListener(dl);
		
		dangling = new JCheckBox("Show Dangling", Stroke.DANGLING);
		dangling.addChangeListener(dl);
		
		add(north);
		add(south, "span, grow");
		add(east);
		add(west, "span, grow");
		add(dangling, "span, grow");
	}

	class DirectionListener implements ChangeListener {
		@Override
		public void stateChanged(ChangeEvent changeEvent) {
			Object source = changeEvent.getSource();
			if (source instanceof JCheckBox) {
				JCheckBox cb = (JCheckBox) source;
				
				if(cb.equals(north))
					if(cb.isSelected())
						Stroke.NORTH = true;
					else
						Stroke.NORTH = false;
				else if(cb.equals(south))
					if(cb.isSelected())
						Stroke.SOUTH = true;
					else
						Stroke.SOUTH = false;
				if(cb.equals(east))
					if(cb.isSelected())
						Stroke.EAST = true;
					else
						Stroke.EAST = false;
				if(cb.equals(west))
					if(cb.isSelected())
						Stroke.WEST = true;
					else
						Stroke.WEST = false;
				if(cb.equals(dangling))
					if(cb.isSelected())
						Stroke.DANGLING = true;
					else
						Stroke.DANGLING = false;
			}
		}
	}
}
